

<script>

import {SysMixin} from '@/mixins/SysMixin'
import defaultSettings from '@/config/defaultSettings'
import ExtForm from '@/components/lt/codeGenerator/components/ExtForm'
import request from '@/utils/request'
import ExtTable from '@/components/lt/codeGenerator/components/ExtTable'
import ExtDrawer from './ExtDrawer'
import ExtModal from './ExtModal'
import ExtRow from '@/components/lt/codeGenerator/components/ExtRow'
import ExtButtonItem from '@/components/lt/codeGenerator/components/ExtButtonItem'
import ExtTree from '@/components/lt/codeGenerator/components/ExtTree'
import ExtQueryForm from '@/components/lt/codeGenerator/components/ExtQueryForm'
import Vue from 'vue'

export default {
    name:'ExtPage',
    components:{
        ExtForm,ExtTable,ExtDrawer,ExtRow,ExtButtonItem,ExtTree,ExtQueryForm
    },
    mixins:[SysMixin],
    data(){
        return{
            Vue,
            defaultSettings,
            pageMethods:null,//页面方法
            pageData:null,//页面数据
            pageMap:new Map(),
        }
      
    },
    created(){
        if(this.$route.meta.pageId){
            this.querySysPage(this.$route.meta.pageId)
        }
        
    },
    watch:{
        // $route:{
        //     handler(val,oldval){
        //         this.pageData=null
        //         if(val.meta.pageId){
        //             if(this.pageMap.get(val.meta.pageId)){
        //                 this.initPage(this.pageMap.get(val.meta.pageId))
        //                 return false
        //             }
        //             this.querySysPage(val.meta.pageId)
        //         }
        //     },
        //     // 深度观察监听
        //     deep: true
        // }
    },

    methods:{
        pageCreate(){},
        initPage(sysPage){
            this.pageData = sysPage.pageData
            this.initDictCodes = sysPage.pageDict
            this.initSysPageMethods(this.pageData.code.methods)
            this.initSysPageData(this.pageData.code.data)
        },
        querySysPage(pageId){
            request.get('/SysPageController/querySysPageById',{params:{pageId:pageId}}).then((res)=>{
                if (res.success) {
                    // console.log(res)
                    res.result.pageData = JSON.parse(require('js-base64').Base64.decode(res.result.pageData))
                    this.pageMap.set(res.result.keyId,res.result)
                    this.initPage(res.result)
                    this.pageCreate()
                } else {
                    this.$message.warning(res.message)
                }
            })
        },

        tableRefresh(ref){
            if(!ref){
                return false
            }
            let table = this.findByRef(this,ref)
            if(!table){
               return false 
            }
            table.refresh()
        }
       
        
    },
    render: function(h) {
        if(this.pageData){
            return(
                <a-card bordered={false}>
                    {this.initSysPageComponents(h,this.pageData.components)}
                    <ExtDrawer ref="ExtDrawer" onClose={this.tableRefresh}></ExtDrawer>
                    
                </a-card>  
            )
        }
            
        
        
    }
}
</script>
